﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;

namespace App.Host
{
    /// <summary>
    /// A Windows service that hosts WCF.
    /// </summary>
    partial class WcfServiceHost : ServiceBase
    {
        #region Fields

        private WcfServiceHostContainer _container = new WcfServiceHostContainer();

        #endregion Fields

        /// <summary>
        /// Initializes a new instance of the <see cref="WcfServiceHost"/> class.
        /// </summary>
        public WcfServiceHost()
        {
            InitializeComponent();

            // Set default service name
            this.ServiceName = "WcfServiceHost";
        }

        /// <summary>
        /// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.
        /// </summary>
        /// <param name="args">Data passed by the start command.</param>
        protected override void OnStart(string[] args)
        {
            // Start all services listed in the application configuration file.
            _container.StartServices();
        }

        /// <summary>
        /// When implemented in a derived class, executes when a Stop command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service stops running.
        /// </summary>
        protected override void OnStop()
        {
            // Stop all services listed in the application configuration file.
            _container.StopServices();
        }
    }
}
